﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace EF.Caching.Impl
{
    /// <summary>
    /// Implémente un cache 'par requête' en encapsulant le éléments du HttpContext.
    /// </summary>
    /// <seealso cref="IPerRequestCache"/>
    public class HttpContextItemsCache : IPerRequestCache
    {
        #region ICache Members

        public object this[string key]
        {
            get
            {
                var context = HttpContext.Current;
                if (context == null) return null;
                else return context.Items[key];
            }
            set
            {
                var context = HttpContext.Current;
                if (context == null) return;
                context.Items[key] = value;
            }
        }

        public bool Contains(string key)
        {
            var context = HttpContext.Current;
            if (context == null) return false;

            return context.Items.Contains(key);
        }

        #endregion
    }
}
